﻿using Microsoft.AspNetCore.Mvc;
using yunbo.Model.RMM;
using yunbo.Repositorys.RMMRepositorys;

namespace yunbo.Controllers.RMMControllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class Rm_yclcgxqController : Controller
    {
        Rm_yclcgxqRepository rm_YclcgxqRepository=new Rm_yclcgxqRepository();
        [HttpPost("Addyclcgxq")]
        public IActionResult Addyclcgxq(TJRm_yclcgxq tjrm_Yclcgxq)
        {
            string currentTime = DateTime.Now.ToString("yyyyMMdd");

            // 生成一个四位随机数
            Random random = new Random();
            int randomNumber = random.Next(1000, 10000); // 生成1000到9999之间的随机数
            string randomNumberString = randomNumber.ToString("D4"); // 格式化为四位数字字符串

            // 组合当前时间和随机数生成ID
            string code = $"cgxq{currentTime}{randomNumberString}";
            Rm_yclcgxq rm_Yclcgxq1 = new Rm_yclcgxq()
            {
                yclcgxq_code = code,
                yclcg_code = tjrm_Yclcgxq.yclcg_code,
                wl_code = tjrm_Yclcgxq.wl_code,
                wl_name = tjrm_Yclcgxq.wl_name,
                yclcg_sl = tjrm_Yclcgxq.yclcg_sl,
                yclcg_dw = tjrm_Yclcgxq.yclcg_dw,
                yclcg_dj = tjrm_Yclcgxq.yclcg_dj,
                yclcg_xj = tjrm_Yclcgxq.yclcg_xj,
                bz = tjrm_Yclcgxq.bz,
                yclcgxq_ydhsl = 0
            };
            bool cg = rm_YclcgxqRepository.Addyclcgxq(rm_Yclcgxq1) > 0;
            return Ok(cg);
        }
        [HttpGet("Getcgxq")]
        public IActionResult Getcgxq(string code)
        {
            Rm_yclcgxq rm_Yclcgxq=rm_YclcgxqRepository.GetRm_Yclcgxq(code);
            return Ok(rm_Yclcgxq);
        }
        [HttpPut("UpDhsl")]
        public IActionResult UpDhsl(decimal ydhsl, string code)
        {
            bool sl=rm_YclcgxqRepository.UpDh(ydhsl, code)>0;
            return Ok(sl);
        }
        [HttpGet("Getrk")]
        public IActionResult Getrk(string code)
        {
            List<Rm_yclcgxq> rk = rm_YclcgxqRepository.Getrk(code);
            return Ok(rk);
        }
        [HttpGet("Getdh")]
        public IActionResult Getdh(string code)
        {
            List<Rm_yclcgxq> dh = rm_YclcgxqRepository.Getdh(code);
            return Ok(dh);
        }
        [HttpPut("Upcgxxsh")]
        public IActionResult Upcgxxsh(UpRm_yclcgxq upRm_Yclcgxq)
        {
            bool sh = rm_YclcgxqRepository.Upgrade(upRm_Yclcgxq) > 0;
            return Ok(sh);
        }
    }
}
